package com.multicampus.simplewiki.model;

import java.util.Collection;

import org.springframework.orm.jpa.support.JpaDaoSupport;

public class TrackBackDAOJPA extends JpaDaoSupport implements TrackBackDAO {

	public void delete(TrackBack trackback) {
		getJpaTemplate().remove(trackback);
	}

	public TrackBack find(int id) {
		return getJpaTemplate().find(TrackBack.class, id);
	}

	public TrackBack insert(TrackBack trackback) {
		getJpaTemplate().persist(trackback);
		return trackback;
	}

	public TrackBack update(TrackBack trackback) {
		getJpaTemplate().merge(trackback);
		return trackback;
	}
	
	public Collection<TrackBack> findByDocument(int documentId){
		return getJpaTemplate().find("select trackback from TrackBack as trackback" +
				" where trackback.document.id = ?", documentId);
	}

}
